package com.zilue.payment.gateway.method.order;

import com.zilue.payment.gateway.domain.CorpDO;
import com.zilue.payment.gateway.exception.BizManagerException;
import com.zilue.payment.gateway.manage.OrderRefundManager;
import com.zilue.payment.gateway.method.BaseMethod;
import com.zilue.payment.gateway.paramter.BaseParameter;
import com.zilue.payment.gateway.paramter.order.RefundParameter;
import com.zilue.payment.gateway.reurndata.PublicReturn;
import com.zilue.payment.gateway.reurndata.enums.RequestStatusEnum;
import com.zilue.payment.gateway.reurndata.order.RefundReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zilue on 2017/3/7.
 */
@Service("hfpay.trade.order.refund")
public class Refund implements BaseMethod {

    @Autowired
    private OrderRefundManager orderRefundManager;

    @Override
    public PublicReturn doMethod(CorpDO corpDO, BaseParameter baseParameter) {
        RefundParameter refundParameter = (RefundParameter) baseParameter;
        //进行退费
        try {
            return orderRefundManager.refund(corpDO, refundParameter);
        } catch (BizManagerException ex) {
            RefundReturn refundReturn = new RefundReturn(RequestStatusEnum.RequestSuccess);
            refundReturn.setBusinessStatus(ex.getBusinessStatusEnum());
            refundReturn.appendSub_msg(ex.getAppendMsg());
            return refundReturn;
        }
    }

    public Class<? extends BaseParameter> paramterClass() {
        return RefundParameter.class;
    }
}
